import 'dart:async';
import 'package:app_admin/utils/logger.dart';
import 'package:app_admin/utils/data_sp.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../routes/app_navigator.dart';

class SplashLogic extends GetxController {
  String? get userID => DataSp.userID;
  String? get token => DataSp.imToken;

  @override
  void onInit() {
    super.onInit();
    //initializedSub = imLogic.initializedSubject.listen((value) {
    // Logger.print('---------------------initialized---------------------');
    // if (null != userID && null != token) {
    //   _login();
    // } else {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      AppNavigator.startLogin();
    });
    // }
    //});

    // Center(
    //   child: ImageRes.splashLogo.toImage
    //     ..width = 55.61.w
    //     ..height = 78.91.h,
    // );
  }

  _login() async {
    // try {
    //   Logger.print('---------login---------- userID: $userID, token: $token');
    //   await imLogic.login(userID!, token!);
    //   Logger.print('---------im login success-------');
    //   pushLogic.login(userID!);
    //   Logger.print('---------push login success----');
    AppNavigator.startSplashToMain(isAutoLogin: true);
    // } catch (e, s) {
    //   IMViews.showToast('$e $s');
    //   await DataSp.removeLoginCertificate();
    //   AppNavigator.startLogin();
    // }
  }

  @override
  void onClose() {
    //initializedSub.cancel();
    super.onClose();
  }
}
